#pragma once


// CImageBtn
class CInitGdiplus
{
public:
	void InitInstance();
	void ExitInstance();
	ULONG_PTR m_gdiplusToken;
};
class CImageBtn : public CButton
{
	DECLARE_DYNAMIC(CImageBtn)

public:
	CImageBtn();
	virtual ~CImageBtn();

protected:
	DECLARE_MESSAGE_MAP()

public:
	// image types
	enum {
		STD_TYPE = 0,
		ALT_TYPE,
		DIS_TYPE
	};
	
	// sets the image type
	void SetImage(int type);
	BOOL LoadAltImage(LPCTSTR pszFileName);
	BOOL LoadStdImage(LPCTSTR pszFileName);
	// if false, disables the press state and uses grayscale image if it exists
	void EnableButton(BOOL bEnable = TRUE) { m_bIsDisabled = !bEnable; }
	// in toggle mode each press toggles between std and alt images
	void EnableToggle(BOOL bEnable = TRUE);
	// return the enable/disable state
	BOOL IsDisabled(void) {return (m_bIsDisabled == TRUE); }

	void SetBkGnd(CDC* pDC);


protected:

	void PaintBk(CDC* pDC);
	void PaintBtn(CDC* pDC);

	BOOL	m_bHaveAltImage;
	BOOL	m_bHaveBitmaps;

	BOOL	m_bIsDisabled;
	BOOL	m_bIsToggle;
	BOOL	m_bIsHovering;
	BOOL	m_bIsTracking;

	int		m_nCurType;

	Image* m_pAltImage;
	Image* m_pStdImage;

	virtual void PreSubclassWindow();
	virtual void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/);
	virtual BOOL PreTranslateMessage(MSG* pMsg);

	afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg LRESULT OnMouseLeave(WPARAM wparam, LPARAM lparam);
	afx_msg LRESULT OnMouseHover(WPARAM wparam, LPARAM lparam) ;


private:

	CDC		m_dcBk;			// button background

	CDC		m_dcStd;		// standard button
	CDC		m_dcStdP;		// standard button pressed
	CDC		m_dcStdH;		// standard button hot

	CDC		m_dcAlt;		// alternate button
	CDC		m_dcAltP;		// alternate button pressed
	CDC		m_dcAltH;		// alternate button hot

	CDC		m_dcGS;			// grayscale button (does not have a hot or pressed state)

	CDC*	m_pCurBtn;		// current pointer to one of the above


public:
	void SizeToContent();	// Call this function to  resize a bitmap button to the size of the bitmap.
};